import { login } from "api/login";
import { Dispatch } from "redux";
import { IAction } from "store";
import userConstant from "../constants/user";

interface LoginParams {
  userName: string;
  password: string;
  captcha: string;
}

export type HandleLogin = (
  params: LoginParams
) => (dispatch: Dispatch<IAction>) => Promise<unknown>;

// 登录
export const handleLogin: HandleLogin = (params) => (dispatch) =>
  login(params).then((res) => {
    let { data } = res;
    dispatch({
      type: userConstant.USER_LOGIN,
      payload: data,
    });
  });
